home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6910 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  990 b 

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: How to get a random strin
  5. Date: 16 Feb 1996 06:51:57 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4g19id$p7n@gail.ripco.com>
  8. NNTP-Posting-Host: golden.ripco.com
  9.  
  10. chancl@nevada.edu (Clapton Chan) in <4fh5od$qq0@news.nevada.edu> asks:
  11.  
  12. >I try to figure out how to get a different string when
  13. >I run the following program.  So far, I always get the
  14. >second string, though I've used the rand() function.
  15.  
  16. 0) Get the FAQ from rtfm.mit.edu.  You should have already done this.
  17.  
  18. 1)  Your code is missing
  19.     #include <stdlib.h>
  20.  
  21. 2) for the following, also
  22.     #include <time.h>
  23. and somewhere shortly after the declarations in main(), insert
  24.     srand(time(NULL));
  25.  
  26. [A poor practice follows]
  27. if you do not #include <time.h>, you need
  28.     srand((unsigned)time(NULL));
  29.                                            
  30. --
  31. * Martin Ambuhl       net: mambuhl@ripco.com
  32. * Chicago, IL (USA)    
  33.